package com.appspot.etao.jdo;

import java.util.Collection;
import java.util.List;

import javax.jdo.PersistenceManager;

public class JDOPersistenceManager<T> {

    private static final PersistenceManager instance = PMF.get().getPersistenceManager();
    
    public static PersistenceManager getInstance() {
    	return instance;
    }
	
    public T insert(T obj) {
    	T dbObj = null;
    	
        try {
            dbObj = instance.makePersistent(obj);
        } finally {
        	instance.close();
        }
    	
        return dbObj;
    }
    
    public Collection<T> insert(List<T> objList) {
    	Collection<T> dbObjList = null;
    	
        try {
        	dbObjList = instance.makePersistentAll(objList);
        } finally {
        	instance.close();
        }
    	
    	return dbObjList;
    }
    
    public void delete(T obj) {
    	instance.deletePersistent(obj);
    }
    
    public void delete(List<T> objList) {
    	instance.deletePersistentAll(objList);
    }
}
